<?php

namespace app\copy\controller;

use Ricoa\CopyWritingCorrect\CopyWritingCorrectService;

class IndexController extends CommonController
{
    /**
     * 首页展示页面
     * @return mixed
     */
    public function index()
    {
        //17 年 10 月 24 日新增 排版指南功能
        return $this->fetch();
    }

    public function copy()
    {
        if (request()->isPost()) {
            $data = input('post.text', '', 'htmlspecialchars');

            if (!empty($data)) {
                // 开始使用 CopyWritingCorrectService 类处理 text 数据
                $service = new CopyWritingCorrectService();

                $content = $service->correct($data);

                return $content;
            }
        } else {
            return '';
        }
    }
}
